//
//  WinnowerAnimationView.swift
//  SwiftUIDemo
//
//  Created by zhouzuosong on 2020/8/20.
//  Copyright © 2020 Kael. All rights reserved.
//

import SwiftUI

struct WinnowerAnimationView: View {
    @State var animationChanged = false
    
    var body: some View {
        VStack {
            
            Text("风车小动画").foregroundColor(.red)
            
            Spacer()

            
            VStack(spacing: 1){
                HStack(alignment: .bottom, spacing: 1){
                    Rectangle()
                        .frame(width: 70, height: 35)
                        .offset(x: !animationChanged ? 0 : -200)
                    Rectangle()
                        .frame(width: 35, height: 70)
                        .offset(y: !animationChanged ? 0 : -200)

                }.offset(x: -18)
                
                HStack(alignment: .top, spacing: 1){
                    Rectangle()
                        .frame(width: 36, height: 72)
                        .offset(y: !animationChanged ? 0 : 200)

                    Rectangle()
                        .frame(width: 72, height: 36)
                        .offset(x: !animationChanged ? 0 : 200)
                    
                }
                .offset(x: 18)
            }
            .foregroundColor(.red)
            .opacity(animationChanged ? 0 : 1)
            .rotationEffect(.degrees(animationChanged ? 0 : -90))
            .foregroundColor(animationChanged ? .orange : .red)
            .animation(.default)
            
            Spacer()

            Button(action: {
                self.animationChanged.toggle()
            }, label: {
                Text("点击开始动画")
            })
            .foregroundColor(.white)
            .padding()
            .background(Color.orange)
            .cornerRadius(8)
            
        }
    }
}

struct WinnowerAnimationView_Previews: PreviewProvider {
    static var previews: some View {
        WinnowerAnimationView()
    }
}
